package lambdasinaction.exercise;

import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author liuchuang
 * @version 1.0
 * @date 2024/1/20 18:03
 * @modify
 */
public class StreamTest {

    public static void main(String[] args) {
        Stream<int[]> pythagoreanTriples =
                IntStream.rangeClosed(1, 100).boxed()
                        .flatMap(a ->
                                IntStream.rangeClosed(a, 100)
                                        .filter(b -> Math.sqrt(a*a + b*b) % 1 == 0)
                                        .mapToObj(b ->
                                                new int[]{a, b, (int)Math.sqrt(a * a + b * b)})
                        );
        pythagoreanTriples.limit(5)
                .forEach(t ->
                        System.out.println(t[0] + ", " + t[1] + ", " + t[2]));

        Stream.iterate(0, n -> n + 2)
                .limit(10)
                .forEach(System.out::println);

        // 
        Stream.iterate(new int[]{0, 1},
                t -> new int[]{t[1], t[0]+t[1]})
                .limit(20)
                .forEach(t -> System.out.println("(" + t[0] + "," + t[1] +")"));
    }

}
